package com.inno.auth.infra.rpc;

import com.inno.auth.common.error.AuthException;
import com.inno.sms.api.SmsFeignService;
import com.inno.sms.dto.SmsInfoDTO;
import com.inno.sms.response.CommonReturnType;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

/**
 * @author sean
 * 短信服务远程调用
 */
@Component
public class SmsRpc {
    @Resource
    private SmsFeignService smsFeignService;

    public void sendSms(SmsInfoDTO smsInfoDTO) {
        CommonReturnType<Void> response = this.smsFeignService.sendSms(smsInfoDTO);
        if (response.getCode() != 200){
            throw new AuthException(response.getMessage());
        }
    }

    public Boolean validate(SmsInfoDTO smsInfoDTO) {
        CommonReturnType<Boolean> response = this.smsFeignService.validate(smsInfoDTO);
        if (response.getCode() != 200){
            return false;
        }
        return response.getContent();
    }
}
